package com.example.juc.demobase;


class Ticket{

    private int numlber=1000;

    public synchronized void sale(){
        if(numlber>0){
            numlber--;
            System.out.println(Thread.currentThread().getName()+" sold "+numlber);
        }
    }

}


public class SaleTicket {
    public static void main(String[] args) {
        Ticket ticket=new Ticket();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i=0;i<300;i++){
                    ticket.sale();
                }
            }
        }, "Thread1");
        thread.start();

        new Thread(()->{
            for(int i=0;i<300;i++){
                ticket.sale();
            }
        }, "Thread2").start();

        for(int i=0;i<100;i++){
                ticket.sale();
        }


    }

}
